package com.springboot.controller;

import com.springboot.model.MessageInform;
import com.springboot.service.DoctorUnreadToReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 本控制台用于点开消息后将消息状态设置为已读
 */
@Controller
public class DoctorUnreadToReadController {
    @Autowired
    DoctorUnreadToReadService doctorUnreadToReadService;

    /**
     * 医生点开消息之后将消息状态设置为已读
     */
    @CrossOrigin
    @RequestMapping(value = "/setReadServlet")
    public @ResponseBody
    String doctorUnreadToRead(@RequestParam("infoId") Integer messageId) {
        System.out.println("医生设置消息为已读");
        try {
            //根据消息编号查找消息记录
            MessageInform messageInform = doctorUnreadToReadService.findMessageById(messageId);
            System.out.println(messageInform.getMessageId());
            messageInform.setMessageState2("已读");
            doctorUnreadToReadService.updateMessageState(messageInform);
            return "True";
        } catch (Exception e) {
            return "False";
        }
    }
}